package sis.studentinfo;

import static org.junit.Assert.assertEquals;
import static sis.util.DateUtil.createDate;

import java.util.Date;

import org.junit.Before;
import org.junit.Test;

import sis.util.DateUtil;



public class CourseSessionTest extends SessionTest{
	
	private CourseSession session;
	private static final int CREDITS = 3;
	
	@Before
	public void setup() {
		this.session = createCourseSession();
	}

	@Test
	public void testCreate() {
		assertEquals("ENGL", session.getDepartment());
		assertEquals("101", session.getNumber());
		assertEquals(0, session.getNumberOfStudents());
	}
	
	@Test
	public void testEnrollStudents() {
		Student student1 = new Student("Cain Divoe");
		session.enrool(student1);
		assertEquals(CREDITS, student1.getCredits());
		assertEquals(1, session.getNumberOfStudents());
		assertEquals(student1, session.get(0));
		
		Student student2 = new Student("Coralee Devaughn");
		session.enrool(student2);
		assertEquals(CREDITS, student2.getCredits());
		assertEquals(2, session.getNumberOfStudents());
		assertEquals(student1, session.get(0));
		assertEquals(student2, session.get(1));
	}
	
	@Test
	public void testCount() {
		CourseSession.resetCount();
		createSession(createCourse(), new Date());
		assertEquals(1, CourseSession.getCount());
		createSession(createCourse(), new Date());
		assertEquals(2, CourseSession.getCount());
	}
	
	private CourseSession createCourseSession() {
		CourseSession session = CourseSession.create(createCourse(), createDate(2003, 1, 6));
		session.setNumberOfCredits(CREDITS);
		return session;
	}
	
	@Test
	public void testCourseDate() {
		Date startDate = DateUtil.createDate(2003, 1, 6);
		Session session = createSession(createCourse(), startDate);
		Date sixteenWeeksOut = createDate(2003, 4, 25);
		assertEquals(sixteenWeeksOut, session.getEndDate());
	}

	private Course createCourse() {
		return new Course("ENGL", "101");
	}

	@Override
	protected Session createSession(Course course, Date startDate) {
		return CourseSession.create(course, startDate);
	}

	
}
